/* @(#)GSOrderCreateNewBatchAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   zhouyijia    2008-7-09  新增创建批次订单
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2007 Auto-Parts E-Procurement Co., Ltd. 
 *        No.251-1 Wuning Road, Shanghai, 200063, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Auto-Parts E-Procurement Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with APEP.
 *
 * Warning:
 * =============================================================================
 *  
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import com.hitrust.gs.business.GSOrderProcesser;
import com.hitrust.gs.form.GSOrderCreateNewBatchForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSOrderDetailModifyVO;

/**
 * 巴士物资级订单明细调整保存
 */
public class GSOrderCreateNewBatchAction extends GSBaseAction {

    public String execute(GSBaseForm aForm) throws Exception {
        //为了在保存调整信息后执行查询，所以调用GSOrderDetailModifyQueryForm
        GSOrderCreateNewBatchForm tForm = (GSOrderCreateNewBatchForm)aForm;
        ArrayList tNewBatchList = new ArrayList();

        if(tForm.orderDetailId != null && tForm.orderDetailId.length > 0){
            //取得当前操作员信息
            for(int i=0; i<tForm.orderDetailId.length; i++){
              
                //如果签收数量未满额则创建分批列表
                GSOrderDetailModifyVO tGSOrderDetailModifyVO = new GSOrderDetailModifyVO();
                tGSOrderDetailModifyVO.orderDetailId   = tForm.orderDetailId[i];
                tGSOrderDetailModifyVO.concentricityId = tForm.concentricityId[i];
                tGSOrderDetailModifyVO.manufName       = tForm.manufName[i];
                tGSOrderDetailModifyVO.providerName    = tForm.providerName[i];
                tGSOrderDetailModifyVO.manufSpec       = tForm.manufSpec[i];
                tGSOrderDetailModifyVO.manufType       = tForm.manufType[i];
                tGSOrderDetailModifyVO.manufBrand      = tForm.manufBrand[i];
                tGSOrderDetailModifyVO.orderCount      = Double.parseDouble(tForm.orderCount[i]);
                tGSOrderDetailModifyVO.quantUnit       = tForm.quantUnit[i];
                tGSOrderDetailModifyVO.deliverGoodsDate = tForm.deliverdate[i];
                tNewBatchList.add(tGSOrderDetailModifyVO);
                
            }
            try{
                GSOrderProcesser tOrderProc = new GSOrderProcesser();
                
                tOrderProc.creatNewBatchOrderDetail(tNewBatchList);

                tForm.getRequest().setAttribute("message","共" + tForm.orderDetailId.length + "笔批次订单创建成功");
                aForm.getRequest().setAttribute("backstep", "-2");
                return GSBaseConstants.FORWARD_SUCCESS;

            }catch(Exception e){
                tForm.getRequest().setAttribute("action","A101301.do");
                throw e;
            }
        }else{
            tForm.getRequest().setAttribute("action","A101301.do");
            throw new GSException(GSException.E00003,GSException.E00003_MSG);
        }
    }

}
